package com.mobilesafe.adapter;

import com.mobilesafe.R;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MainUIAdapter extends BaseAdapter {
	private static final String TAG = "MainUIAdapter";
	private LayoutInflater inflater;
	private static ImageView iv_icon;
	private static TextView tv_name;
	private static View view;
	private Context context;

	public MainUIAdapter(Context context) {
		this.context = context;
		inflater = LayoutInflater.from(context);
	}

	public static String[] names = { "手机防盗", "通讯卫士", "软件管理", "任务管理", "流量管理",
			"手机杀毒", "系统优化", "高级工具", "设置中心" };

	public static int[] icons = {
			R.drawable.activity_main_private_space_iconselector,
			R.drawable.activity_main_sms_iconselector,
			R.drawable.activity_main_software_iconselector,
			R.drawable.activity_main_protection_iconselector,
			R.drawable.activity_main_start_adview_check_iconselector,
			R.drawable.activity_main_start_adview_check_iconselector,
			R.drawable.activity_main_sync_iconselector,
			R.drawable.activity_main_protection_iconselector,
			R.drawable.activity_main_protection_iconselector,
			R.drawable.activity_main_start_adview_check_iconselector};

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return names.length;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// getview的方法被调用了多少次?
				// 9
				// gridview 控件bug 
				// won't fix 
				// 使用静态的变量引用 减少内存中申请的引用的个数 
				
				Log.i(TAG,"getview: "+ position);
				view = inflater.inflate(R.layout.activity_main_item, null);
				iv_icon =  (ImageView) view.findViewById(R.id.iv_main_item_icon);
				tv_name =  (TextView) view.findViewById(R.id.tv_main_item_name);
				iv_icon.setImageResource(icons[position]);
				tv_name.setText(names[position]);
				
		return view;
	}

}
